//
//  ShowViewController.m
//  QXShowing
//
//  Created by 王道道 on 2018/4/11.
//  Copyright © 2018年 doll_dream. All rights reserved.
//

#import "ShowViewController.h"

#import "VTMagicController.h"
#import "ShowListPageViewController.h"
#import "YBPopupMenu.h"

static NSString *const listVC1 = @"listVC1";
static NSString *const listVC2 = @"listVC2";
static NSString *const listVC3 = @"listVC3";

@interface ShowViewController ()<VTMagicViewDelegate,VTMagicViewDataSource,YBPopupMenuDelegate>
@property (nonatomic, strong) VTMagicController *magicController;
@property (nonatomic, strong) UIButton *rightButton;
@property (nonatomic, strong) NSArray *yearArray;

@end

@implementation ShowViewController

#pragma mark - Lazy
- (VTMagicController *)magicController {
    if (_magicController == nil) {
        _magicController = [[VTMagicController alloc]init];
        _magicController.magicView.frame = CGRectMake(0, 0, App_Frame_Width, App_Frame_Height - kNavbarAndStatusBar);
        _magicController.magicView.navigationColor = [UIColor whiteColor];
        _magicController.magicView.backgroundColor = [UIColor whiteColor];
//        _magicController.magicView.layoutStyle = VTLayoutStyleDivide;
        _magicController.magicView.layoutStyle = VTLayoutStyleDefault;
        _magicController.magicView.switchStyle = VTSwitchStyleDefault;
        _magicController.magicView.sliderColor = Main_Color;
        _magicController.magicView.itemScale = 1.2;
        _magicController.magicView.sliderWidth = 20;
        _magicController.magicView.sliderHeight = 3;
        _magicController.magicView.scrollEnabled = YES;
        _magicController.magicView.delegate = self;
        _magicController.magicView.dataSource = self;
    }
    return _magicController;
}

//- (void)viewWillAppear:(BOOL)animated {
//    [super viewWillAppear:animated];
//    [self.navigationController setNavigationBarHidden:YES animated:YES];
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [self initNavBar:@"近期展览"];
    self.title = self.hallTitle;
    
    [self initNavBarBackBtn];
    [self initRightBtn];
    self.yearArray = @[@"2018",@"2017",@"2016",@"2015",@"2014",@"2013",@"2012",@"2011",@"2010"];

    [self addChildViewController:self.magicController];
    [self.view addSubview:self.magicController.magicView];
    [self.magicController.magicView reloadData];
}

- (void)initRightBtn {
    self.rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 25)];
    [self.rightButton setTitle:@"2018" forState:UIControlStateNormal];
    [self.rightButton addTarget:self action:@selector(rightItemClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.rightButton setTitleColor:Text_Color_333333 forState:UIControlStateNormal];
    self.rightButton.titleLabel.font = BHFont_Size_15;
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:self.rightButton];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)rightItemClick:(UIButton *)sender {
    [YBPopupMenu showRelyOnView:sender titles:self.yearArray icons:nil menuWidth:120 otherSettings:^(YBPopupMenu *popupMenu) {
//        popupMenu.backColor = [UIColor colorWithHexString:@"#EEEEEE"];
        popupMenu.backColor = [UIColor colorWithHexString:@"#FFFFFF"];
        popupMenu.textColor = Text_Color_333333;
        popupMenu.fontSize = 12 * SizeScale;
        popupMenu.itemHeight = 34;
        popupMenu.delegate = self;
        popupMenu.showMaskView = NO;
    }];
}

#pragma mark - YBPopupMenuDelegate
- (void)ybPopupMenuDidSelectedAtIndex:(NSInteger)index ybPopupMenu:(YBPopupMenu *)ybPopupMenu {
    [self.rightButton setTitle:self.yearArray[index] forState:UIControlStateNormal];
//    [self.view reloadInputViews];
//    BaseViewController *vc = self.magicController.currentViewController;
    if ([self.magicController.currentViewController isKindOfClass:[ShowListPageViewController class]]) {
        ShowListPageViewController *vc = self.magicController.currentViewController;
        vc.year = self.rightButton.titleLabel.text;
        [vc.tableView headerRefresh];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIButton *)magicView:(VTMagicView *)magicView menuItemAtIndex:(NSUInteger)itemIndex {
    static NSString *itemIdentifier = @"itemIdentifier";
    UIButton *menuItem = [magicView dequeueReusableItemWithIdentifier:itemIdentifier];
    if (!menuItem) {
        menuItem = [UIButton buttonWithType:UIButtonTypeCustom];
        [menuItem setTitleColor:Text_Color_333333 forState:UIControlStateNormal];
        [menuItem setTitleColor:Main_Color forState:UIControlStateSelected];
        menuItem.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:16.f];
    }
    return menuItem;
}

- (NSArray<NSString *> *)menuTitlesForMagicView:(VTMagicView *)magicView {
    return @[@"全部",@"1月份",@"2月份",@"3月份",@"4月份",@"5月份",@"6月份",@"7月份",@"8月份",@"9月份",@"10月份",@"11月份",@"12月份"];
}

- (UIViewController *)magicView:(VTMagicView *)magicView viewControllerAtPage:(NSUInteger)pageIndex {
    ShowListPageViewController *listVCc = [magicView dequeueReusablePageWithIdentifier:listVC3];
    if (!listVCc) {
        listVCc = [[ShowListPageViewController alloc] init];
    }
    listVCc.cityId = self.cityId;
    listVCc.Id = self.Id;
    listVCc.page = pageIndex;
    
    listVCc.year = self.rightButton.titleLabel.text;
    [listVCc.tableView headerRefresh];
    return listVCc;
}


- (void)magicView:(VTMagicView *)magicView viewDidAppear:(__kindof UIViewController *)viewController atPage:(NSUInteger)pageIndex {
//    if (pageIndex == 0) viewController.view.backgroundColor = [UIColor redColor];
//    else if (pageIndex == 1) viewController.view.backgroundColor = [UIColor greenColor];
//    else if (pageIndex == 2) viewController.view.backgroundColor = [UIColor blueColor];
//    else if (pageIndex == 3) viewController.view.backgroundColor = [UIColor yellowColor];
//    else viewController.view.backgroundColor = [UIColor purpleColor];

//    else if (pageIndex == 5) viewController.orderStatusType = OrderStatusTypeProcessed;
//    else viewController.orderStatusType = OrderStatusTypePendingEvaluation;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
